// 筛选条件转换相应id
export const chinesetoId = (chinese) => {
  let arr = [{
    cond_id: 1,
    cond_str: '年份',
    cond_word: 'year'
  }, {
    cond_id: 2,
    cond_str: '学历',
    cond_word: 'xl'
  }, {
    cond_id: 3,
    cond_str: '专业',
    cond_word: 'zy'
  }, {
    cond_id: 4,
    cond_str: '地市',
    cond_word: 'addr'
  }, {
    cond_id: 5,
    cond_str: '县区',
    cond_word: 'xianqu'
  }]
  let tmp = []
  for (let a = 0; a <= arr.length; a++) {
    for (let v = 0; v <= chinese.length; v++) {
      if (arr[v].cond_str == chinese[a]) {
        tmp.push(arr[v].cond_id)
      }
    }
  }
  return tmp
}
// id转筛选条件
export const idToChinese = (id) => {
  let arr = [{
    cond_id: 1,
    cond_str: '年份',
    cond_word: 'year'
  }, {
    cond_id: 2,
    cond_str: '学历',
    cond_word: 'xl'
  }, {
    cond_id: 3,
    cond_str: '专业',
    cond_word: 'zy'
  }, {
    cond_id: 4,
    cond_str: '地市',
    cond_word: 'addr'
  }, {
    cond_id: 5,
    cond_str: '县区',
    cond_word: 'xianqu'
  }]
  let tmp = []
  id.filter(item => {
    arr.map(element => {
      if (element.cond_word == item) {
        tmp.push(element.cond_str)
      }
    })
  })
  return tmp
}
// 批量替换数组对象key
export const replaceKey = (arr, key) => {
  let newArr = [];
  arr.forEach((item, index) => {
    let newObj = {};
    for (var i = 0; i < key.length; i++) {
      newObj[key[i]] = item[Object.keys(item)[i]]
    }
    newArr.push(newObj);
  })
  return newArr;

}



export default {
  chinesetoId,
  idToChinese
}
